package controllers

import (
	"newAi/new_web/models"
)

type ParamRecordController struct {
	BaseController
}

func (self *ParamRecordController) List() {
	self.Data["pageTitle"] = "变量管理"
	//暂且留着  ，到时候效果好的话，就用这个
	tpl_id,_:=self.GetInt64("tplid")
	list := models.ParamGetListByTape(tpl_id)
	self.Data["tab1"] = list[0]
	self.Data["tab2"] = list[1]
	self.Data["tab3"] = list[2]
	self.Data["tab4"] = list[3]
	self.Data["tab5"] = list[4]
	self.Data["tab6"] = list[5]
	self.Data["tpl_id"] = tpl_id

	self.display()
}

func (self *ParamRecordController) Edit() {
	self.Data["pageTitle"] = "变量编辑"
	self.Data["audio"] = self.GetString("audio")

	self.display()
}

//上传语音文件
func (self *ParamRecordController) Upload() {
	path, err := self.UploadFile("/opt/fsgui/nway-sys/sounddir/param/", "uploadField")

	if err == nil {
		//models.ProcessContentAdd()
		self.ajaxMsg(path, MSG_OK)
	} else {
		self.ErrorLog(err)
	}

}

func (self *ParamRecordController) AjaxSave(){
	param := new(models.AIVoiceLibrary)
	param.Process_id,_ = self.GetInt64("tpl_id")
	param.Voice_path = self.GetString("path")
	param.Voice_type = self.GetString("type")
	param.Topic = self.GetString("pNmae")

	_,err:=models.VoiceLibraryAdd(param)
	if err != nil {
		self.ErrorLog(err)
		self.ajaxMsg(err.Error(), MSG_ERR)
	}
	self.ajaxMsg("", MSG_OK)
}

func (self *ParamRecordController) ParamListByType(){
	param := new(models.AIVoiceLibrary)
	param.Voice_path = self.GetString("path")

	_,err:=models.VoiceLibraryAdd(param)
	if err != nil {
		self.ErrorLog(err)
		self.ajaxMsg(err.Error(), MSG_ERR)
	}
	self.ajaxMsg("", MSG_OK)
}
